#include "Level.h"

Level::Level(int levelId) : m_amountOfRooms(0), m_roomType(-1), m_pCurrentRoom(NULL) 
{
	//Seeds the random generator for constructing the amount of rooms 
	//in a given level
	srand((unsigned int)time(NULL));

	//Information about how many rooms which should be in the level.
	//There will always be one room
	m_amountOfRooms = (rand() % MAXIMUM_ROOMS) + 1;

	//Condition to ensure that the level is built correctly
	if(!buildLevel())
	{
		MessageBox(0, "Level could not be built!", 0, 0);
	}
}

Level::~Level()
{
	delete m_pCurrentRoom;
}

bool Level::buildLevel()
{ 
	//Condition to ensure that the
	//amount of rooms are less than that of the
	//constant for the Maximum numver of rooms
	if(m_amountOfRooms < 1)
	{
		m_amountOfRooms = 1;
	}
	else if(m_amountOfRooms > MAXIMUM_ROOMS)
	{
		m_amountOfRooms = MAXIMUM_ROOMS;
	} 


	//If the level was not built the result
	//returned will be false
	return false;
}

void Level::resetLevel()
{

}

void Level::goToRoom(int roomId)
{
	//This nested loop will check through the multi-dimensional array
	//for the matching roomId

	//Cycles through the matrix horizontally
	for(int row = 0; row < LEVEL_WIDTH; row++)
	{
		//Cycles through the matrix vertically
		for(int col = 0; col < LEVEL_HEIGHT; col++)
		{
			//Condition for checking to see if the 
			//room ids match if they do, then the 
			//room becomes the currently viewable room
			if(m_rooms[row][col].getRoomId() == roomId)
			{
				m_pCurrentRoom = &m_rooms[row][col];
			}
		}
	}
}